package utils.test

import org.springframework.context.support.FileSystemXmlApplicationContext;
import com.mycompany.app.util.SpringUtils;

/**
 * Convenient class for initializing spring context automatically with specific xml files directory.
 * Simple fuction test classes can extend this class and get beans from SpringUtils.
 * author: shawn.guo
 */
class BaseTestUtils {
	static{
	    File baseSpringConfigDir=new File(/D:\personal\sky-drive\src\main\resources/);
	    ArrayList appContextFileArray=new ArrayList();
	    
	    baseSpringConfigDir.eachFileRecurse{
	        if(!it.isDirectory()&&it.getName()==~/applicationContext.*xml/)
	        {
	            println "identify ApplicationContext:"+it.getName()
	            appContextFileArray.add(it.getPath())
	        }
	    }
	    
	    println appContextFileArray
	    
	    String[] cons=new String[appContextFileArray.size()];
	    for(int i in 0..appContextFileArray.size()-1)
	    {
	        cons[i]=appContextFileArray.get(i);
	    }
	    FileSystemXmlApplicationContext context=new FileSystemXmlApplicationContext(cons);
	    println context
	    println "spring context initialize successfully.."
	    println "----------------------------------------------------------------------------------"
	}
}